package cn.liuhuan1.blogsModel.controller;

import cn.liuhuan1.api.MongoDbClent;
import cn.liuhuan1.entity.ReturnResult;
import cn.liuhuan1.webModelBean.api.MongoDbImp;
import cn.liuhuan1.webModelBean.vo.ArticleCommentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: liuhuan
 * @Date: 2021/4/19 - 04 - 19 - 20:06
 * @Description:
 * @version: 1.0
 */
@Controller
@RequestMapping("/mongoDb")
public class MongoDbController {

    @Autowired
    private MongoDbImp mongoDbImp;


    @RequestMapping(value = "/insert",method = RequestMethod.POST)
    @ResponseBody
    public ReturnResult insert(@RequestBody ArticleCommentVo articleCommentVo){
        mongoDbImp.insert(articleCommentVo);
        return ReturnResult.succes();
    }

    @RequestMapping(value = "/insertAll",method = RequestMethod.POST)
    @ResponseBody
    public ReturnResult insertAll(@RequestBody List<ArticleCommentVo> articleCommentVoList){
        mongoDbImp.insertAll(articleCommentVoList);
        return ReturnResult.succes();
    }

    @RequestMapping(value = "/findAll",method = RequestMethod.GET)
    @ResponseBody
    public ReturnResult findAll(@RequestParam("articleId") String articleId){
        List<ArticleCommentVo> all = mongoDbImp.findAll(articleId);
        return ReturnResult.succes(all);
    }

    @ResponseBody
    @RequestMapping(value = "/likeNumber",method = RequestMethod.POST)
    public ReturnResult likeNumber(@RequestParam("id") String id,@RequestParam("likeNumber") Integer likeNumber){
        mongoDbImp.likeNumber(id,likeNumber);
        return ReturnResult.succes();
    }
}
